﻿/** 初始化UI */
function initui() {
	// alert("iui");
	dwr.engine.setActiveReverseAjax(true);
	dwr.engine.setNotifyServerOnPageUnload(true, true);
	// ConsoleUIMethods.initUser();
	Methods.getOrderList();
}

function sel() {
	var selstate = document.getElementById("selstate").value;
	if (selstate == "true") {// 做全选操作
		select_all();
		document.getElementById("selstate").value = "false";
	} else {
		noselect_all();
		document.getElementById("selstate").value = "true";
	}
}
function select_all() { // 全选
	var inputs = document.getElementsByTagName("input");
	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].getAttribute("type") == "checkbox") {
			inputs[i].checked = true;
		}
	}
}
function noselect_all() { // 全不选
	var inputs2 = document.getElementsByTagName("input");
	for (var i = 0; i < inputs2.length; i++) {
		if (inputs2[i].getAttribute("type") == "checkbox") {
			inputs2[i].checked = false;
		}
	}
}
function msgparam(id) {

	$('#myModal').on('show.bs.modal', function(event) {
		var button = $(event.relatedTarget); // Button that triggered the
		// modal
		var recipient = button.data('whatever'); // Extract info from data-*
		// attributes

		var modal = $(this)
		modal.find('.modal-title').text('New message to ' + recipient);
		modal.find('.body input').val(recipient);
	});

}

function dlview(odid) {
	// alert("dlview");
	var downloadurl = Methods.getDownloadURL(odid);

}
function dlview2(dlurl) {
	if (dlurl == "-1") {
		alert("没有找到文件！");
	} else {
		window
				.open(
						'download.jsp?isview=true&dlurl=' + dlurl,
						"download",
						'toolbar=no,menubar=no,scrollbars=no, resizable=yes,location=no, status=no',
						true);

	}
}
function createDlg(str) {
	var u = document.getElementById("s12");
	u.insertAdjacentHTML("beforeEnd", str);

}
function exportInfo() {
	$('#odtable').tableExport({
		type : 'excel',
		escape : 'false'
	});

}
function dostate(odid, pstate) {
	// alert("odid="+odid+" pstate="+pstate);

	switch (pstate) {
	case 0:

		swal({
			title : "确定重启流程？",
			type : "warning",
			showCancelButton : true,
			confirmButtonColor : "#DD6B55",
			confirmButtonText : "重启",
			cancelButtonText : "取消",
			closeOnConfirm : false,
			closeOnCancel : false
		}, function(isConfirm) {
			if (isConfirm) {
				Methods.reBootOd(odid);
			} else {
				swal({
					title : "您已取消操作",
					text : "",
					type : "error",
					timer : 1000
				});
			}
		});
		break;
	case 1:
		swal({
			title : "确定该问题已处理完成？",
			type : "warning",
			showCancelButton : true,
			confirmButtonColor : "#DD6B55",
			confirmButtonText : "完成",
			cancelButtonText : "取消",
			closeOnConfirm : false,
			closeOnCancel : false
		}, function(isConfirm) {
			if (isConfirm) {
				Methods.doFinish(odid);
			} else {
				swal({
					title : "您已取消操作",
					text : "",
					type : "error",
					timer : 1000
				});
			}
		});

		break;
	case 2:
		swal("暂未开放", "", "info");
		// Methods.setInvalid(odid);
		break;
	case 3:

		swal({
			title : "确定作废本条问题？",
			type : "warning",
			showCancelButton : true,
			confirmButtonColor : "#DD6B55",
			confirmButtonText : "作废",
			cancelButtonText : "取消",
			closeOnConfirm : false,
			closeOnCancel : false
		}, function(isConfirm) {
			if (isConfirm) {
				Methods.setInvalid(odid);
			} else {
				swal({
					title : "您已取消操作",
					text : "",
					type : "error",
					timer : 1000
				});
			}
		});

		break;

	default:
		break;
	}
}
function updateodinfo(odid, pstate) {
	var lp = document.getElementById("pstate" + odid);
	var zfBtn = document.getElementById("zf" + odid);
	var wcBtn = document.getElementById("wc" + odid);
	var cqBtn = document.getElementById("cq" + odid);

	var divBtn = document.getElementById("divbtn" + odid);
	switch (pstate) {
	case 0:
		lp.innerHTML = "<span class='label label-warning'>待处理</span>";
		zfBtn.removeAttribute("disabled");
		wcBtn.setAttribute("disabled", "disabled");
		cqBtn.setAttribute("disabled", "disabled");
		swal({
			title : "重启成功!",
			text : "该条问题状态置为未处理",
			type : "success",
			timer : 2000
		});
		break;
	case 1:
		lp.innerHTML = "<span class='label label-inverse'>已处理</span>";
		zfBtn.setAttribute("disabled", "disabled");
		wcBtn.setAttribute("disabled", "disabled");
		cqBtn.removeAttribute("disabled");
		swal({
			title : "已处理!",
			text : "该条问题已处理完成",
			type : "success",
			timer : 2000
		});
		break;
	case 2:
		lp.innerHTML = "<span class='label label-success'>处理中</span>";
		zfBtn.setAttribute("disabled", "disabled");
		wcBtn.removeAttribute("disabled");
		cqBtn.removeAttribute("disabled");
		break;
	case 3:
		lp.innerHTML = "<span class='label label-danger'>已作废</span>";
		zfBtn.setAttribute("disabled", "disabled");
		wcBtn.setAttribute("disabled", "disabled");
		cqBtn.removeAttribute("disabled");
		swal({
			title : "已处理!",
			text : "该条问题作废",
			type : "success",
			timer : 2000
		});

		break;

	default:
		alert("系统繁忙！");
		break;
	}
	// alert(divBtn.innerHTML);
}
function selctr1(odid) {
	var lb = document.getElementById('lb' + odid);
	var str = lb.innerHTML;
	switch (str) {
	case '处理中':
		document.getElementById('plzf').setAttribute('disabled', 'disabled');
		document.getElementById('plwc').removeAttribute('disabled');
		document.getElementById('plcq').removeAttribute('disabled');
		break;
	case '已作废':

		document.getElementById('plzf').setAttribute('disabled', 'disabled');
		document.getElementById('plwc').setAttribute('disabled', 'disabled');
		document.getElementById('plcq').removeAttribute('disabled');
		break;
	case '已完成':
		document.getElementById('plzf').setAttribute('disabled', 'disabled');
		document.getElementById('plwc').setAttribute('disabled', 'disabled');
		document.getElementById('plcq').removeAttribute('disabled');

		break;
	case '待处理':
		document.getElementById('plzf').removeAttribute('disabled');
		document.getElementById('plwc').setAttribute('disabled', 'disabled');
		document.getElementById('plcq').setAttribute('disabled', 'disabled');
		document.getElementById('dcxz').setAttribute('disabled', 'disabled');

		break;

	default:
		break;
	}

}
function loadingctr(isshow) {

	switch (isshow) {
	case 'h':
		document.getElementById("loading").style.display = "none";// 隐藏
		break;

	case 'v':
		document.getElementById("loading").style.display = "";// 显示
		break;
	default:
		break;
	}

}
function outputTable() {//导出为excel
	var tb = document.getElementById('odtable');
	var tbhtml = '';
	var json = {};
	var title = {};
	var data = {};

	var t1 = tb.rows[0].cells[1].innerHTML;
	var t2 = tb.rows[0].cells[2].innerHTML;
	var t3 = tb.rows[0].cells[3].innerHTML;
	var t4 = tb.rows[0].cells[4].innerHTML;

	title["t1"] = t1;
	title["t2"] = t2;
	title["t3"] = t3;
	title["t4"] = t4;
	json["title"] = title;

	for (var i = 1; i < tb.rows.length; i++) {
		var d = {};
		for (var j = 1; j < 5; j++) {
			
			tbhtml = tb.rows[i].cells[j].innerHTML;
			d[j] = tbhtml;
		}
		data["data_" + i] = d;
	}
	json["data"] = data;
	
var jsonStr=JSON.stringify(json);
	 Methods.toExcel(jsonStr);
}
function toExcel_sel() {
	var inputs2 = document.getElementsByTagName("input");

	var tb = document.getElementById('odtable');
	var tbhtml = '';
	var json = {};
	var title = {};
	var data = {};

	var t1 = tb.rows[0].cells[1].innerHTML;
	var t2 = tb.rows[0].cells[2].innerHTML;
	var t3 = tb.rows[0].cells[3].innerHTML;
	var t4 = tb.rows[0].cells[4].innerHTML;

	title["t1"] = t1;
	title["t2"] = t2;
	title["t3"] = t3;
	title["t4"] = t4;
	json["title"] = title;

       var n=1;
	for (var i = 1; i < tb.rows.length; i++) {
		if (inputs2[i].checked == true) {
			//alert(i);
		var d = {};
		for (var j = 1; j < 5; j++) {
			tbhtml = tb.rows[i].cells[j].innerHTML;
			d[j] = tbhtml;
		}
		data["data_" + n] = d;
n++;
		}else{
			
		}
	}
	if(n==1){
		swal({
			title : "",
			text : "您未选择任何记录",
			type : "warning",
			timer : 2000
		});
		return;
	}
	json["data"] = data;
	
var jsonStr=JSON.stringify(json);
	 Methods.toExcel(jsonStr);
}